package com.doit.day01


object _06_for循环 {
  def main(args: Array[String]): Unit = {
    val arr: Array[Int] = Array(1, 2, 3, 4)
    for (elem <- arr) {

    }

    //序列
//    val seq: Range.Inclusive = 0 to 99



    //循环步长  by  revers 反转
    for (elem <- 0 until 10 by 3 reverse) {
//      println(elem)
    }
    //打印0-9中的所有的数，但是我不想要5
    for (elem <- 0 until 10) {
      if(elem != 5){
//        println(elem)
      }
    }

    println("===============")
    //循环守卫
    for (elem <- 0 until 10 if elem != 5) {
//        println(elem)
    }

    //引入变量
    for(i <- 1 to 3; j = 4 - i) {
//      println("i=" + i + " j=" + j)
    }

    var j = 0
    for(elem <- 1 to 3){
      j = 4 - elem
//      println("i=" + elem + " j=" + j)
    }

    //双重for循环
    for(i <- 1 to 9){
      for(j <- 1 to i ){
        print(s"${i} * ${j} = ${i*j} \t")
      }
      println()
    }

    println("===================")

    for(i <- 1 to 9;j <- 1 to i){
      print(s"${i} * ${j} = ${i*j} \t")
      if (i == j ) println()
    }

    //1 to 10 前闭后闭   1 until 10 前闭后开
    //by 循环步长
    //reverse 反转
    // 引入变量
    //循环守卫
    //双重for循环





  }
}
